﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using TransactionServer.General_Classes;

namespace TransactionServer.OSActivities
{

    public sealed class OSDelete : CodeActivity
    {
        // Define an activity input argument of type string
        public InArgument<Context> Context { get; set; }
        public InArgument<Entity> Entity { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            Entity entity = context.GetValue(this.Entity);
            Context con = context.GetValue(this.Context);
            OSConnector conn = (OSConnector)con.Connector[entity.System];

            Event evnt = new Event(DateTime.Now, "Delete", entity);

            try
            {
                conn.Delete(entity);
            }
            catch (Exception ex)
            {
                throw new SystemOperationException(entity, ex);
            }
        }
    }
}
